package com.baosight.risk.web.xtzy;

import java.util.List;

import javax.ws.rs.core.MediaType;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baosight.risk.api.xtzy.IXtzyCompRoleService;
import com.baosight.risk.base.controller.BaseController;
import com.baosight.risk.common.annotation.Log;
import com.baosight.risk.common.result.AjaxResult;
import com.baosight.risk.service.xtzy.entity.XtzyCompRole;

import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;

/**
 * 
 * @author zzw
 *
 */
@Slf4j
@RestController
@RequestMapping("/xtzy/comprole")
@Api(value = "组织机构", description = "组织机构", produces = MediaType.APPLICATION_JSON)
public class XtzyCompRoleController extends BaseController {

    @Autowired
    private IXtzyCompRoleService compRoleService;

    @PostMapping("saveHomePage")
    @Log(title = "维护首页")
    public AjaxResult saveHomePage(@RequestBody List<XtzyCompRole> compRoleList) throws Exception {
        if (CollectionUtils.isEmpty(compRoleList)) {
            return error("数据为空");
        }
        
        for(XtzyCompRole compRole : compRoleList){
        	compRole.setId(compRole.getExt3());
        	compRole.setExt1(null);
        	compRole.setExt2(null);
        	compRole.setExt3(null);
        	compRoleService.save(compRole);
        }
        return toAjax(compRoleList.size());
    }

}
